// pages/my/controladdr/addr-list/addrList.js
import { areaList } from '@vant/area-data';



Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    textareaSize: {
      maxHeight: 150, 
      minHeight: 80
    },
    areaList,
    show: false,
    username:'',
    phone:'',
    areaStr:'请选择',
    addrDetail:'',
    values:[]
  },

  onSave(e){
    const prevAddress = wx.getStorageSync('address') || [];
    let address = {
      username:this.data.username,
      phone:this.data.phone,
      areaStr:this.data.areaStr,
      addrDetail: this.data.addrDetail
    }
    if(this.data.username==''){
      wx.showModal({
        title: '提示',
        content:'请填写您的名字'
      })
    }else if(this.data.phone == ''){
      wx.showModal({
        title: '提示',
        content:'请填写您的电话号码'
      })
    }else if(!(/^1(3|4|5|7|8)\d{9}$/.test(this.data.phone))){
      wx.showModal({
        title: '提示',
        content:'手机号格式不正确哦'
      })
    }
    else if(this.data.values == ''){
      wx.showModal({
        title: '提示',
        content:'请选择您的所在区域'
      })
    }else if(this.data.addrDetail == ''){
      wx.showModal({
        title: '提示',
        content:'请填写您的详细地址'
      })
    }else{
      wx.setStorageSync('address', prevAddress.concat(address))
      wx.navigateBack();
    }
  },
  showPopup() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  onConfirm(e) {
    // console.log(e);
    const values = e.detail.values;
    const areaStr = values.map(value => value["name"]).join('');
    
    this.setData({
      values,
      areaStr,
      show: false
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log(options);
      //  this.setData({
      //   username:.username,
      //   phone:.phone,

      // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})